//
//  DialogCont.swift
//  OnemeetingDemo
//
//  Created by 张衡 on 2020/4/24.
//  Copyright © 2020 www.onemeeting.1meetingIos. All rights reserved.
//

import Foundation

typealias BtnTapBlock = ((ZHButton)->())

class DialogCont: NSView {
    
    var confirmAction:BtnTapBlock?
    var cacalAction:BtnTapBlock?
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        self.setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        self.addSubview(contentLab)
        contentLab.snp.makeConstraints { (make) in
            make.width.equalToSuperview()
            make.height.equalTo(40)
            make.top.equalTo(0)
            make.left.equalToSuperview()
        }
        
        self.addSubview(confirmBtn)
        confirmBtn.snp.makeConstraints { (make) in
            make.width.equalTo(60)
            make.height.equalTo(36)
            make.right.equalTo(-20)
            make.bottom.equalTo(0)
        }
        
        self.addSubview(cacalBtn)
        cacalBtn.snp.makeConstraints { (make) in
            make.width.equalTo(60)
            make.height.equalTo(36)
            make.right.equalTo(confirmBtn.snp.left).offset(-20)
            make.bottom.equalTo(0)
        }
    }
    
    lazy var contentLab: NSTextField = {
        let lab = NSTextField.label(title: "内容已更新", textColor: color_gray(120), font: NSFont.systemFont(ofSize: 14))
        lab.maximumNumberOfLines = 0
        return lab
    }()
    
    lazy var confirmBtn: ZHButton = {
        let btn = ZHButton.init(frame: NSRect.zero)
        btn.zh_title = "更新"
        btn.zh_backgroundColor = color_main140
        btn.zh_font = NSFont.systemFont(ofSize: 14)
        btn.zh_color = NSColor.white
        btn.hasBorder = true
        btn.zh_cornerRadius = 10
        btn.target = self
        btn.action = #selector(confirmBtnAction(senber:))
        return btn
    }()
    
    lazy var cacalBtn: ZHButton = {
        let btn = ZHButton.init(frame: NSRect.zero)
        btn.zh_title = "取消"
        btn.zh_font = NSFont.systemFont(ofSize: 14)
        btn.zh_color = NSColor.black
        btn.zh_backgroundColor = color_gray(240)
        btn.hasBorder = true
        btn.zh_cornerRadius = 10
        btn.zh_borderColor = color_gray(200)
        btn.zh_borderWidth = 1
        btn.target = self
        btn.action = #selector(cacalBtnAcion(senber:))
        return btn
    }()
    
    
    @objc func cacalBtnAcion(senber:ZHButton) {
        if cacalAction != nil {
            self.cacalAction!(senber)
        }
        Dialog.shared.dismiss()
    }
    
    @objc func confirmBtnAction(senber:ZHButton) {
        if confirmAction != nil {
            self.confirmAction!(senber)
        }
        Dialog.shared.dismiss()
    }
    
    
}

